#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->lineEdit->setText("A");
    ui->lineEdit->installEventFilter(this);

}

Widget::~Widget()
{
    delete ui;
}

bool Widget::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == ui->lineEdit) {
        if (event->type() == QEvent::Enter) {
            ui->lineEdit->setText("B");
        } else if (event->type() == QEvent::Leave) {
            ui->lineEdit->setText("A");
        }
    }
    // 对于我们不感兴趣的事件，返回 false 以确保它们被正常处理
    return QObject::eventFilter(obj, event);
}

//void Widget::enterEvent(QEvent *event){
//    ui->lineEdit->setText("B");
//}

//void Widget::leaveEvent(QEvent *event){
//    ui->lineEdit->setText("A");
//}
